
import serial
import time


vel = 0
ser = serial.Serial('COM11', 115200)

# 发送命令函数
def send_command(command):
    ser.write(command.encode())
    time.sleep(0.1)
# 全部归零
def stop_all_func():
    global vel
    vel = 0
    send_command(f":0 {vel}\r\n")
    send_command(f":1 {vel}\r\n")
    send_command(f":2 {vel}\r\n")
    send_command(f":3 {vel}\r\n")
# 速度挡位
def vel_1_func():
    global vel
    vel = 10
def vel_2_func():
    global vel
    vel = 20
def vel_3_func():
    global vel
    vel = 30
def vel_4_func():
    global vel
    vel = 40
def vel_5_func():
    global vel
    vel = 50
# 导丝导管运动
def wire_push_button():
    global vel
    if vel < 0:
        vel = -vel
    send_command(f":2 {vel}\r\n")
    send_command(f":3 {vel}\r\n")
def wire_pull_button():
    global vel
    if vel > 0:
        vel = -vel
    send_command(f":2 {vel}\r\n")
    send_command(f":3 {vel}\r\n")

    
def wire_cw_button():
    global vel
    if vel < 0:
        vel = -vel
    send_command(f":1 {vel}\r\n")

    
def wire_ccw_button():
    global vel
    if vel > 0:
        vel = -vel
    send_command(f":1 {vel}\r\n")

    
def cath_push_button():
    global vel
    if vel < 0:
        vel = -vel
    send_command(f":0 {vel}\r\n")

    
def cath_pull_button():
    global vel
    if vel > 0:
        vel = -vel
    send_command(f":0 {vel}\r\n")

    